#include "../../include/thread/threadHandle.h"
#include "../../include/global.h"
#include "boost/format.hpp"
#include "sys/socket.h"
#include "syslog.h"

//数据发送线程
void ThreadSendData(void)
{
    boost::format fmt;

    //启动
    fmt = boost::format("数据发送线程启动成功");
    syslog(LOG_INFO,fmt.str().c_str());

    //等待唤醒并发送数据
    while(true)
    {
        std::unique_lock<std::mutex> lc(gmtDataSend);
        gcvDataSend.wait(lc,[](){return gQueDataSend.size() > 0?true:false;});

        DataSend dataSend = gQueDataSend.front();
        send(dataSend.sockfd,dataSend.data.c_str(),dataSend.data.length(),0);
        gQueDataSend.pop();

        gcvDataSend.notify_all();
    }
   
    //关闭
    fmt = boost::format("数据发送线程结束");
    syslog(LOG_INFO,fmt.str().c_str());
}